import store from '@/store';
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
  {
    path: '/',
    redirect: "/home",
  },
  {
    path: '/book',
    name: 'book',
    component: () => import('../views/bookView.vue')
  },
  {
    path: '/shopping',
    name: 'shopping',
    component: () => import('../views/shoppingView.vue')

  },
  {
    path: '/myorder',
    name: 'myorder',
    component: () => import('../views/myorderView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }

  },
  {
    path: '/shoppingcar',
    name: 'shoppingcar',
    component: () => import('../views/shoppingcarView.vue')

  },
  {
    path: '/addaddress',
    name: 'addaddress',
    component: () => import('../views/addaddressView.vue'),

  },
  {
    path: '/minemessage',
    name: 'minemessage',
    component: () => import('../views/minemessageView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }

  },
  {
    path: '/libraries',
    name: 'libraries',
    component: () => import('../views/librariesView.vue')

  },
  {
    path: '/settlement',
    name: 'settlement',
    component: () => import('../views/settlementView.vue')

  },
  {
    path: '/addreslocal',
    name: 'addreslocal',
    component: () => import('../views/addreslocalView.vue')

  },
  {
    path: '/video',
    name: 'video',
    component: () => import('../views/videoView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }

  },
  {
    path: '/study',
    name: 'study',
    component: () => import('../views/studyView.vue')

  },
  {
    path: '/coupon',
    name: 'coupon',
    component: () => import('../views/couponView.vue')

  },
  {
    path: '/talkabout',
    name: 'talkabout',
    component: () => import('../views/talkaboutView.vue')

  },
  {
    path: '/Down',
    name: 'Down',
    component: () => import('../views/DownView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }

  },
  {
    path: '/addresslocal',
    name: 'addresslocal',
    component: () => import('../views/addresslocalView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }

  },
  {
    path: '/aboutour',
    name: 'aboutour',
    component: () => import('../views/aboutourView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }

  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/homeView.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/myView.vue')
  },
  {
    path: '/netshop',
    name: 'netshop',
    component: () => import('../views/netshopView.vue'),
  },
  {
    path: '/serach',
    name: 'serach',
    component: () => import('../views/serachbookView.vue'),
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/loginView.vue'),
  },
  {
    path: '/reg',
    name: 'reg',
    component: () => import('../views/registeredView.vue'),
  },
  {
    path: '/pay',
    name: 'pay',
    component: () => import('../views/payView.vue'),
  },
  {
    path: '/television',
    name: 'television',
    component: () => import('../views/televisionView.vue'),
  },
  {
    path: '/classlesson',
    name: 'classlesson',
    component: () => import('../views/classlessonView.vue'),
  },
  {
    path: '/collecView',
    name: 'collecView',
    component: () => import('../views/collecView.vue'),
    beforeEnter: (to, from, next) => {
      let token = store.state.phone
      // 判断是否登录
      if (!token) {
        next("/login");
        return;
      } else {
        next();
      }
    }
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
